// pages/goods_detail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houseObj: {}
  },
  HouseInfo: {},
  /**
   * 生命周期函数--监听页面加载
   */
  // onLoad: function (options) {
  //   const { _id } = options;
  //   this.getHouseInfo(_id);
  // },

  onShow: function () {
    let pages = getCurrentPages();
    let currentPage = pages[pages.length - 1];
    let options = currentPage.options;
    const { _id } = options;
    this.getHouseInfo(_id);
  },

  // 获取房屋信息
  getHouseInfo(_id) {
    let that = this
    const db = wx.cloud.database()
    wx.showLoading({
      title: "加载中"
    });
    db.collection('house_information').where({ _id: _id }).get({
      success: function (res) {
        wx.hideLoading();
        that.HouseInfo = res;
        that.setData({
          houseObj: res.data[0]
        })
      }
    })
  },
  // 预览图片
  handlePreviewImage(e) {
    const urls = this.HouseInfo.data[0].pics.map(v => v.image_src);
    const current = e.currentTarget.dataset.url;
    console.log(current);
    wx.previewImage({
      current,
      urls
    });
  }
})